<template>
    <div class="school">
        <h2>学校名称:{{ name }}</h2>
        <h2>学校地址:{{ address }}</h2>
    </div>
</template>

<script>
import Vue from 'vue';
import pubsub from 'pubsub-js'
export default Vue.extend({
    name: 'Student',
    data() {
        return {
            name: "尚硅谷atguigu",
            address: "北京",
        }
    },
    mounted() {
        // this.$bus.$on('hello', (data) => {
        //     console.log('我是School组件，我收到了：', data);
        // })

        // pubsub的使用有点像定时器，需要把 它的id拿到 然后用id销毁该订阅
        this.pubId = pubsub.subscribe('hello', (subMsg, data) => {
            console.log('我是School组件，我收到了：', data);
        })
    },
    beforeDestroy() {
        // this.$bus.$off('hello')
        pubsub.unsubscribe(this.pubId)
    }
}) 
</script>

<style>
.school {
    background-color: skyblue;
    padding: 5px;
}
</style>